//
//  ISDUETHomeViewController.m
//  12Cung
//
//  Created by Tran Bao Thai on 8/5/12.
//  Copyright (c) 2012 Tran Bao Thai. All rights reserved.
//

#import "ISDUETHomeViewController.h"
#import "ISDUETRotaryWheel.h"
#import "ISDUETHoangDaoViewController.h"
#import "ISDUETTableNewsViewController.h"
#import "Constants.h"
#import "ISDUETIntroduceViewController.h"

@interface ISDUETHomeViewController (){
    int currentSelectedSector;
}

@end

#define WHEEL_FRAME         CGRectMake(0 , 0, 240, 240)

@implementation ISDUETHomeViewController
@synthesize lblSelectedSector;
@synthesize btnCenter;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}


- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = YES;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.navigationController.navigationBarHidden = YES;
    
    ISDUETRotaryWheel* wheelControl = [[[ISDUETRotaryWheel alloc]initWithFrame:WHEEL_FRAME andDelegate:self withSections:4]autorelease];
    wheelControl.center = btnCenter.center;//CGPointMake(160, 240);
    [self.view insertSubview:wheelControl belowSubview:btnCenter];
}

- (void)viewDidUnload
{
    [self setLblSelectedSector:nil];
    [self setBtnCenter:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)dealloc {
    [lblSelectedSector release];
    [btnCenter release];
    [super dealloc];
}

- (void) wheelDidChangeValue:(NSString *)newValue withCurrentSector:(int)sectorValue {
    
    self.lblSelectedSector.text = newValue;
    currentSelectedSector = sectorValue;
    
}

- (void) ISDUETIntroduceVCDidFinished:(ISDUETIntroduceViewController*)introduceVC{
    [self dismissModalViewControllerAnimated:YES];
}

- (void) pressedCenterButtonWithCurrentSector:(int)sectorValue{
    
}
- (IBAction)btnCenterPressed:(UIButton *)sender {
    NSLog(@"Selected sector at index: %i", currentSelectedSector);
    
    switch (currentSelectedSector) {
        case 0:
        {
            ISDUETTableNewsViewController* tvhnVC = [[[ISDUETTableNewsViewController alloc]initWithNibName:@"ISDUETTableNewsViewController" bundle:nil]autorelease];
            tvhnVC.typeOfNew = HD_TVHN;
            [self.navigationController pushViewController:tvhnVC animated:YES];
        }
            break;
        case 1:
        {
            ISDUETTableNewsViewController* tvhnVC = [[[ISDUETTableNewsViewController alloc]initWithNibName:@"ISDUETTableNewsViewController" bundle:nil]autorelease];
            tvhnVC.typeOfNew = HD_TINTUC;
            [self.navigationController pushViewController:tvhnVC animated:YES];
        }
            break;
        case 2:
        {
            ISDUETHoangDaoViewController* hoangdaoVC = [[[ISDUETHoangDaoViewController alloc]initWithNibName:@"ISDUETHoangDaoViewController" bundle:nil]autorelease];
            [self.navigationController pushViewController:hoangdaoVC animated:YES];
        }
            break;
        case 3:
        {
            ISDUETIntroduceViewController* introduceVC = [[[ISDUETIntroduceViewController alloc]initWithNibName:@"ISDUETIntroduceViewController" bundle:nil]autorelease];
            introduceVC.introduceDelegate = self;
            introduceVC.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
            [self presentModalViewController:introduceVC animated:YES];
        }
            break;
        default:
            break;
    }
}
@end
